package cn.edu.xmu.oomall.payment.util;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import java.util.LinkedHashMap;
import java.util.Map;

public class PaymentCommon {
    public static Object decorateReturnObject(PaymentReturnObject returnObject) {
        Map<String, Object> obj = new LinkedHashMap<>();
        obj.put("code", returnObject.getCode());
        if(returnObject.getMessage()!=null){
            obj.put("message", returnObject.getMessage());
        }else{
            obj.put("message", returnObject.getCode().getMessage());
        }
        switch (returnObject.getCode()) {
            case SUCCESS:
            case FAIL:
                // 200
                return new ResponseEntity(obj,HttpStatus.OK);

            default:
                return obj;
        }
    }

}
